import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

main() => runApp(MyApp());

// 生成代码快捷键  stl
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: GLHomePage(),
    );
  }
}

class GLHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text("基础的widget"),
        ),
        body: const GLHomeContent());
  }
}

class GLHomeContent extends StatefulWidget {
  const GLHomeContent({super.key});

  @override
  State<GLHomeContent> createState() => _GLHomeContentState();
}

class _GLHomeContentState extends State<GLHomeContent> {
  @override
  Widget build(BuildContext context) {
    /*
    * Stack 默认大小事包裹内容的
    * 左上角开始布局
    * alignment:从什么位置开始布局子widget
    * fit：expand 将子元素拉伸到尽可能大
    * overflow:超出部分处理
    * 
    * Positioned
    * */
    return Stack(
      children: [
        Image.asset(
          "assets/images/scent_woman.jpg",
        ),
        Positioned(
            right: 0,
            left: 0,
            bottom: 0,
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 8),
              color: Color.fromARGB(150, 0, 0, 0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    "闻香识人",
                    style: TextStyle(fontSize: 30, color: Colors.white),
                  ),
                  IconButton(
                      onPressed: () => print("点击收藏"),
                      icon: Icon(Icons.favorite, color: Colors.white)),
                  // GestureDetector(
                  //   child: Icon(
                  //     Icons.favorite,
                  //     color: Colors.white,
                  //   ),
                  // )
                ],
              ),
            ))
      ],
    );
  }
}

class STackDemo extends StatelessWidget {
  const STackDemo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: AlignmentDirectional.bottomCenter, // 定位
      // fit: StackFit.expand,
      children: [
        Image.asset(
          "assets/images/scent_woman.jpg",
          width: 300,
        ),
        Positioned(
            left: 100,
            bottom: 0,
            child: Container(
              width: 150,
              height: 150,
              color: Colors.blue,
            )),
        Positioned(
            right: 60,
            bottom: 20,
            child: Text(
              "闻香识人",
              style: TextStyle(fontSize: 30),
            ))
      ],
    );
  }
}
